#include "stdafx.h"
#include "HotKeyCompare.h"

namespace HotKeyCompare
  {
//------------------------------------------------------------------------

  template struct CompareBy<CompareByID>;
  template struct CompareBy<CompareByName>;
  template struct CompareBy<CompareByKeys>;

//------------------------------------------------------------------------

  template<class CompareByProperty>
  bool CompareBy<CompareByProperty>::operator ()(HotKey & i_hot_key)
    {
    return static_cast<CompareByProperty*>(this)->IsEqual(i_hot_key);
    }

//------------------------------------------------------------------------

  template<class CompareByProperty>
  bool CompareBy<CompareByProperty>::operator ()(HotKey * ip_hot_key)
    {
    return (*this)(*ip_hot_key);
    }

//------------------------------------------------------------------------

  template<class CompareByProperty>
  bool CompareBy<CompareByProperty>::operator ()(boost::shared_ptr<HotKey> & ip_hot_key)
    {
    return (*this)(ip_hot_key.get());
    }

//------------------------------------------------------------------------
//------------------------------------------------------------------------

  CompareByID::CompareByID(int i_id)
    :m_id(i_id)
    {
    }

//------------------------------------------------------------------------

  bool CompareByID::IsEqual(HotKey & i_hot_key)
    {
    return m_id == i_hot_key.GetID();
    }

//------------------------------------------------------------------------

  CompareByName::CompareByName(std::wstring & i_name)
    :m_name(i_name)
    {
    }

//------------------------------------------------------------------------

  bool CompareByName::IsEqual(HotKey & i_hot_key)
    {
    return m_name == i_hot_key.GetName();
    }

//------------------------------------------------------------------------

  CompareByKeys::CompareByKeys(HotKey::KeyCode i_vk_code, HotKey::Modifier i_modifiers)
    :m_vk_code(i_vk_code)
    ,m_modifiers(i_modifiers)
    {
    }

//------------------------------------------------------------------------

  bool CompareByKeys::IsEqual(HotKey & i_hot_key)
    {
    return m_vk_code == i_hot_key.GetVKCode() &&
      m_modifiers == i_hot_key.GetModifiers();
    }

//------------------------------------------------------------------------

  }